
#include "types.h"
#include "user.h"
#include "stat.h"

#define N  20
#define P  50

void
forktest(void)
{
  int n, pid, sid;

  printf(1, "fork test\n");
	pid = getpid();
  for(n=0; n<N; n++){
		sid = fork();
    if(sid == 0)
		{
			pid = getpid();
      break;
		}
  }
  
	sleep(10);
	if (sid != 0)
	{
		for (n=0; n < N; n++)
		{
			wait();
		}
		exit();
	}
	else
	{
		for (n=0; n < P; n++)
		{
			printf(1, "Process %d is printing for %d time\n", pid, n);
		}
		exit();
	}
  
}

int
main(void)
{
  enableSwapping();
  forktest();
  exit();
}
